import { Component, EventEmitter, Injector, Output, ViewChild } from '@angular/core';
import { AppComponentBase } from '@shared/common/app-component-base';
import { ModalDirective } from 'ngx-bootstrap';
import {
    DtoExtensionsDemoServiceProxy,
    GetEditDtoExtensionsDemoOutput,
    DtoExtensionsDemoEditDto,
    EditDtoExtensionsItem
} from '@shared/service-proxies/stock-service-proxies';

@Component({
    selector: 'createOrEditDtoExtenstionsModal',
    templateUrl: './create-or-edit-dto-extensions-modal.component.html'
})
export class CreateOrEditDtoExtenstionsModalComponent extends AppComponentBase {
    @ViewChild('createModal') modal: ModalDirective;

    @Output() modalSave: EventEmitter<any> = new EventEmitter<any>();

    active = false;
    saving = false;

    editDto: DtoExtensionsDemoEditDto;
    extensions: Array<EditDtoExtensionsItem>;
    optionAll;

    constructor(injector: Injector, private _dtoExtensionsService: DtoExtensionsDemoServiceProxy) {
        super(injector);
    }

    show(editionId?: number): void {
        this.active = true;

        this._dtoExtensionsService.getEditDtoExtensionsDemo().subscribe(result => {
            this.optionAll = {
                selectOptions: result.selectOptions,
                multiSelectOptions: result.multiSelectOptions
            };
            this.editDto = result.dtoExtensionsDemo;
            this.extensions = result.items;
            // this.extensions.forEach(el => {
            //     if (el.type === 6 || el.type === 7) {
            //         if (this.editDto[el.key]) {
            //             this.editDto[el.key] = this.editDto[el.key].toDate();
            //         }
            //     }
            // });

            this.modal.show();
        });
    }

    onShown(): void {}

    save(): void {}

    close(): void {
        this.active = false;
        this.modal.hide();
    }
}
